package com.yanqu.road.server.cmd.drugstore;

import com.yanqu.road.pb.drugstore.DrugStoreProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.drugstore.DrugStoreModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_DRUG_STORE_RECEPT_PATIENT, desc = "营业/接收病人")
public class DrugReceptPatientCmd extends AbstractCommand {

    boolean isOneKey;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {

        DrugStoreProto.DrugReceptPatientReqMsg reqMsg = DrugStoreProto.DrugReceptPatientReqMsg.parseFrom(packet.getBytes());
        isOneKey = reqMsg.getIsOneKey();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {

        if(isOneKey){
            ret = player.getModule(DrugStoreModule.class).receivePatientOneKey(null, false);
        } else {
            ret = player.getModule(DrugStoreModule.class).receivePatient();
        }

    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_DRUG_STORE_RECEPT_PATIENT, DrugStoreProto.DrugReceptPatientRespMsg.newBuilder().setRet(ret));
        }
    }
}
